if(1)
  arbbeta = 1;
  arbmu = 1;
  [H, Kernel] = CreateKernel( arbbeta, arbmu );
  isInvKernel = 1;
  if( isInvKernel == true )
    global invKernel;
    invKernel = inv(Kernel);
  end
  nLevel = 4;
  [DiagVec, DiagBlock, RKBlock] = ConstructGreen( Kernel, nLevel );
  [L,U,K] = periodic_tridiag_prepare(Kernel);
end

nx = length(Kernel);
nTest = 5*log2(nx);
arrCol = ceil( nx * rand( nTest, 1 ) );
err = zeros( nTest, 1 );
for i = 1 : nTest
  u = zeros(nx, 1);
  u(arrCol(i)) = 1;

  v = U\(L\u);
  v = v - K*[v(1);v(end)];
   % v = Kernel\u;
   % plot(u);
   % pause;  
  err(i) = abs( v(arrCol(i)) - DiagVec(arrCol(i)) ) ./ abs(v(arrCol(i)));
  % err(i)
end
max(err)

if( isInvKernel )
  display('Checking diagonal blocks');
  nSample = 2^nLevel;
  nList = nx / nSample;
  nWidthCur = nList / 2;
  Err2 = zeros( nSample, 1 );
  for i = 1 : nSample * 2
    Err2(i) = norm( DiagBlock{i} - invKernel( ...
      1+(i-1)*nWidthCur : i * nWidthCur, ...
      1+(i-1)*nWidthCur : i * nWidthCur ) );
    Err2(i)
  end
end
